#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"
#include"zdym/msg/tms.hpp"
#include<ctime>
#include<string>
void gettime(zdym::msg::Tms & mm){
    time_t t=time(nullptr);
    struct tm* now=localtime(&t);
    std::stringstream tms;
    mm.year=1900+now->tm_year;
       mm.mongth=1+now->tm_mon;
       mm.day=now->tm_mday;
        mm.hour=now->tm_hour;
        mm.minute=now->tm_min;
       mm.second=now->tm_sec;
}
using namespace std::chrono_literals;
class pub:public rclcpp::Node{
    public :
    pub():Node("pub")
    {
        puber_=this->create_publisher<zdym::msg::Tms>("time",10);
        timer_=this->create_wall_timer(500ms,std::bind(&pub::timer_callback,this));
    }
    private:
    void timer_callback(){
        auto message=zdym::msg::Tms();
        gettime(message);
        // RCLCPP_INFO(this->get_logger(),message.data.c_str());
        puber_->publish(message);

    }
    rclcpp::TimerBase::SharedPtr timer_;
    rclcpp::Publisher<zdym::msg::Tms>::SharedPtr puber_;
};
int main(int argc,char *argv[]){
    rclcpp::init(argc,argv);
    rclcpp::spin(std::make_shared<pub>());
    rclcpp::shutdown();
    return 0;
}